package com.ruoyi.web.controller.repair;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.projectInfo.domain.HouseProjectInfoT;
import com.ruoyi.projectInfo.service.IHouseProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维修内容Controller
 * 
 * @author tuyeqi
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/repair/projectInfo")
public class HouseProjectInfoController extends BaseController
{
    @Autowired
    private IHouseProjectInfoService houseProjectInfoService;

    /**
     * 查询维修内容列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseProjectInfoT houseProjectInfo)
    {
        startPage();
        List<HouseProjectInfoT> list = houseProjectInfoService.selectHouseProjectInfoList(houseProjectInfo);
        return getDataTable(list);
    }

    /**
     * 导出维修内容列表
     */
    @Log(title = "维修内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseProjectInfoT houseProjectInfo)
    {
        List<HouseProjectInfoT> list = houseProjectInfoService.selectHouseProjectInfoList(houseProjectInfo);
        ExcelUtil<HouseProjectInfoT> util = new ExcelUtil<HouseProjectInfoT>(HouseProjectInfoT.class);
        util.exportExcel(response, list, "维修内容数据");
    }

    /**
     * 获取维修内容详细信息
     */
   @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return AjaxResult.success(houseProjectInfoService.selectHouseProjectInfoByInfoId(infoId));
    }

    /**
     * 新增维修内容
     */
    @Log(title = "维修内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseProjectInfoT houseProjectInfo)
    {
        houseProjectInfo.setCreater(getUsername());
        return toAjax(houseProjectInfoService.insertHouseProjectInfo(houseProjectInfo));
    }

    /**
     * 修改维修内容
     */
   @Log(title = "维修内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseProjectInfoT houseProjectInfo)
    {
        return toAjax(houseProjectInfoService.updateHouseProjectInfo(houseProjectInfo));
    }

}
